$(function(){
	//放入购物车
	var $btnAddCart = $('#btnAddCart');
	var $goods_number = $('#goods_number');

	$btnAddCart.click(function(){
		
		var goods_number = parseInt($.trim($goods_number.val()));
		
		if(isNaN(goods_number)){
			alert('请填写正确的购买数量');
			return false;
		}
		
		var goods_id 	= $goods_number.attr('goods_id');
		var goods_attr 	=  $('input[name="attrs"]:checked').val();
		
		addCart(goods_id,goods_number,goods_attr);
	});
	
	
	//切换属性重新计算金额
	var	$attrs = $('input[name="attrs"]');
	$attrs.change(function(){
		subtotal();
	});
	
	//数量切换
	$goods_number.change(function(){
		subtotal();
	});
	
	//选中第一个属性
	$($attrs[0]).attr('checked',true);
	subtotal();
	
	
	//菜单划入切换
	$('#ul-tab li').hover(
		function(){
			$(this).find('a').click();
		},
		function(){
			
		}
	);
	
	
	var ie = isIE();
	if(ie){
		nameSetPosition();
	}
	
});

//小计金额
function subtotal(){
	
	var attr_price 		= $('input[name="attrs"]:checked').attr('price');
	var goods_number 	= parseInt($.trim($('#goods_number').val()));

	var subtotal = parseFloat(attr_price) * parseInt(goods_number);
	
	$('#subtotal').html(subtotal.toFixed(2) + '元');
}

function nameSetPosition(){
	var $goods_ename = $('#goods_ename');
	if($goods_ename.length > 0){
		$goods_ename.css({'position':'absolute','top':'19px','left':'120px'});
	}
}